﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

namespace MOWebApplication
{
    public partial class MOWebApplication : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private static void TryGetWebLinkResponse(string url)
        {
            try
            {
                {
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

                    HttpWebResponse respons;

                    respons = (HttpWebResponse)request.GetResponse();

                    StreamReader reader = new StreamReader(respons.GetResponseStream());
                    string contents = reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        protected void layerCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            string url;
            string usrName = "alex";

            Guid imgGuid = Guid.NewGuid();
            url = "http://localhost/scripts/esrimap.dll?name=MOclient&username=" + usrName
                + "&imgguid=" + imgGuid.ToString();
            url += "&cmd=layerVisib";

            url += String.Format("&layer1Visible={0}&layer2Visible={1}&layer3Visible={2}&layer4Visible={3}&layer5Visible={4}&layer6Visible={5}", layer1Checkbox.Checked.ToString(), 
                layer2Checkbox.Checked.ToString(), layer3Checkbox.Checked.ToString(), layer4Checkbox.Checked.ToString(), layer5Checkbox.Checked.ToString(), layer6Checkbox.Checked.ToString());

            TryGetWebLinkResponse(url);            
            Image imgProduct = ContentPlaceHolder1.FindControl("imgProduct") as Image;
              
            imgProduct.ImageUrl = "~/ImageHandler/ImageHandler.ashx?imgName="
               + imgGuid
               + "&usrName=" + usrName;
            Session["imgGuid"] = imgGuid;
        }

        protected void zoomIn_Click(object sender, EventArgs e)
        {
            hdnSelectedTool.Value = "ZoomIn";            
        }

        protected void zoomOut_Click(object sender, EventArgs e)
        {
            hdnSelectedTool.Value = "ZoomOut";            
        }

    }
}
